package com.wk.warehouse.service.impl;

import java.util.HashMap;
import java.util.List;

import com.wk.warehouse.entity.InStore;
import com.wk.warehouse.entity.Purchase;
import com.wk.warehouse.mapper.PurchaseMapper;
import com.wk.warehouse.page.Page;
import com.wk.warehouse.service.PurchaseService;
import com.wk.warehouse.util.WarehouseConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestHeader;


@Service
public class PurchaseServiceImp implements PurchaseService {
	
	@Autowired
	private PurchaseMapper purchaseMapper;

	/**
	 * 查询满足搜索条件的数据条数
	 */
	@Override
	public int selectCount(Purchase purchase) {
		return purchaseMapper.selectCount(purchase);
	}

	/**
	 * 分页查询的数据
	 */
	@Override
	public List<Purchase> purchasePageQuery(Purchase purchase, Page page) {
		HashMap<String, Object> map = new HashMap<>();
		map.put("purchase", purchase);
		map.put("page", page);
		return purchaseMapper.purchasePageQuery(map);
	}

	/**
	 * 生成入库单
	 */
	@Override
	public int addInWarehouseRecord(InStore inStore, int buyId) {
		// 添加入库单
		purchaseMapper.addInWarehouseRecord(inStore);
		// 修改入库状态为已入库
		return purchaseMapper.updateInState(buyId);
	}

	/**
	 * 添加新的采购单
	 */
	@Override
	public int addPurchase(Purchase purchase) {
		return purchaseMapper.addPurchase(purchase);
	}

	/**
	 * 更新采购单
	 */
	@Override
	public int updatePurchase(Purchase purchase) {
		return purchaseMapper.updatePurchase(purchase);
	}

	/**
	 * 删除采购单
	 */
	@Override
	public int deletePurchase(int buyId) {
		return purchaseMapper.deletePurchase(buyId);
	}
}
